<template>
    <div>
        <div class="nav">
            <div class="left">
                <div class="time">下午好</div>
                <div class="name">
                    <router-link to="/Login">
                        登录
                    </router-link>
                </div>
            </div>
            <div class="right">
                <van-search shape="round" v-model="value" placeholder="请输入搜索关键词" @focus="searchFocus" />
            </div>
        </div>

        <!-- 轮播图 -->
        <div class="swipe">
            <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
                <van-swipe-item v-for="(item, index) in bannerlist">
                    <img class="auto" :src="item.bannerImg" alt="" />
                </van-swipe-item>

            </van-swipe>
        </div>

        <!-- 商品start -->
        <div class="product-list" style=" padding-bottom: 100px;">
            <!-- 热卖banner -->
            <div class="bestSellers">
                <div style=" ">热卖推荐 :</div>
            </div>
            <div class="products">
                <!-- 商品 -->
                <div class="products-card" v-for="(item, index) in shoplist1">
                    <div class="img-box" @click="getProcq(item.pid, index)">
                        <img :src="item.smallImg" alt="" style="border-radius: 15px; height: 90%;width: 90%;margin-top: 10px;" />
                    </div>
                    <div class="info">
                        <div class="name one_text">{{ item.name }}</div>
                        <div class="enname one_text">{{ item.enname }}</div>
                        <div class="price">￥{{ item.price }}</div>
                    </div>
                    <div class="hot">hot</div>
                </div>
            </div>

        </div>

        <div class="none">木有啦 ~ 不要再划了 ~</div>


    </div>
</template>

<script>
import { get } from "../request";
import { ref } from "vue";
import { useRouter } from "vue-router";
//轮播图数据
const getSwipeDataEff = () => {
    //存放轮播图数据
    const bannerlist = ref([]);
    //获取轮播图数据
    const getSwipe = async () => {
        const res = await get('/banner');
        console.log("轮播图数据", res);
        bannerlist.value = res.data.result;
    }
    getSwipe();
    return { bannerlist, getSwipe }
}
export default {
    setup() {
        //属性、方法

        //存放商品
        const shoplist1 = ref([])
        const getShop = async () => {
            const res = await get("/typeProducts", {
                params: {
                    key: 'isHot',
                    value: 1
                }
            })
            shoplist1.value = res.data.result

            console.log("商品信息", res);
        }
        getShop()

        //点击进入商品详情页
        const getProcq = (e) => {
            //console.log("e", e);
            router.push({ name: "Detail", query: { id: e } })
        }


        //搜索跳转
        const router = useRouter();
        const searchFocus = () => {
            router.push('/Search');
        }
        const { bannerlist, getSwipe } = getSwipeDataEff();
        return {
            bannerlist,
            getSwipe,
            searchFocus,
            getShop,
            getProcq,
            shoplist1
        }
    }
}
</script>

<style lang="less" scoped>
.bestSellers {
    margin-left: 10px;
    border-radius: 5px;
    width: 95px;
    height: 25px;
    background-color: #182078;
    color: #fff;
    font-size: 18px;
    text-align: center;
}

.products {
    display: flex;
    justify-content: space-around;
    align-items: center;
    flex-wrap: wrap;
}

.products-card {
    position: relative;
    width: calc(100% / 2 - 10px);
    margin: 5px;
    border-radius: 10px;
    text-align: center;
    background-color: #ffffff;
    height: 245px;
}



.name one_text {
    font-size: 16px;
    font-weight: 700;
    margin: 2px;
}

.enname one_text {
    font-size: 12px;
    color: #acacac;
    margin: 5px 10px;
}

.price {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 10px;
    color: #182078;
}

.hot {
    position: absolute;
    top: 6px;
    right: 5px;
    width: 30px;
    height: 15px;
    text-align: center;
    line-height: 15px;
    background-color: #182078;
    color: #fff;
}

.none {
    text-align: center;
    font-size: 12px;
    font-weight: 100;
    margin-bottom: 50px;
    margin-top: -60px;
}

/deep/.van-swipe__indicator--active {
    background-color: rgb(138, 36, 234) !important;
}

/deep/.van-swipe__indicator {
    background-color: rgb(201, 152, 248);
}

/deep/.van-swipe__indicator {
    width: 10px;
    height: 3px;
    border-radius: 0;
}

/deep/.van-swipe__indicators {
    left: 87%;
}

.swipe {
    margin: 6px;
    border-radius: 10px;
    overflow: hidden;
}

.my-swipe .van-swipe-item {
    color: #fff;
    font-size: 20px;
    //line-height: 150px;
    text-align: center;
    //background-color: #39a9ed;
}

/deep/.van-field__left-icon .van-icon,
.van-field__right-icon .van-icon {
    color: rgb(138, 36, 234);
}


.nav {
    display: flex;
    align-items: center;
    height: 54px;

    .left {
        width: 110px;
        height: 100%;
        background-color: #fff;
        display: flex;
        align-items: center;

        .time {
            margin: 0 15px 0;
        }

        // .name {}
    }

    .right {
        flex: 1;
        background-color: coral;

    }
}</style>